
--[[
1 所有对象的基类

--]]

local Object = require "object"

--回调的好手
function handler(obj, method)
    return function(...)
        if not method then
            g.log:error("handler:", obj:getObjName(), method)
            return
        end
        local ok, res = pcall(method, obj, ...)
        if not ok then
            g.log:error("handler:", obj:getObjName(), method, res)
            return
        end
        return res
    end
end

--新建一个对象
function new(mod_name, ...)
    local ok, Class = pcall(require, mod_name)
    if ok and Class and Class.isObject then
        --print("class new " .. mod_name)
        local ok, obj = pcall(Class.new, Class, ...)
        if not ok or not obj then
            --print("############new obj error ", mod_name, obj)
            g.log:error("new obj error: ", mod_name, obj)
            return
        end
        obj:setModuleName(mod_name)
        if g and type(g) == "table" and g.addObj then
            g.addObj(obj)
        else
            error("new obj g.lua is not ready ! " .. mod_name .. " error")
        end
        return obj
    end
    g.log:error("new obj error: " .. mod_name, Class)
    return nil
end

--声明一个类，继承Object
function class(name)
    local cls = Object:extend(name)
    return cls
end


